<!--[if ie 6]>
      <style type="text/css">
      div#content div.buttonMinibox{width:200px;display:inline;float:none;overflow: hidden;}
      div#content div.buttonBox{width:600px;height:30px;}
      </style>
<![endif]-->

<?php
	echo "<script language='javascript'>

	function mostrarAba(id) {
		abaVisivel = document.getElementById('AssistidoAbaVisivel').value;
		document.getElementById('aba'+abaVisivel).style.display = 'none';

		document.getElementById('AssistidoAbaVisivel').value = id;
		document.getElementById('aba'+id).style.display = '';

		/* Modifica a cor da aba */
		document.getElementById('atab'+abaVisivel).className = 'tabBegin';
		document.getElementById('litab'+abaVisivel).className = 'tabEnd';

		document.getElementById('atab'+id).className = 'tabBeginSelected';
		document.getElementById('litab'+id).className = 'tabEndSelected';
	}

	</script>";
	echo $accessibility->whereIAm($pageTitle);
	echo $this->renderElement('message');
	echo "<h2 id='contentTitle'>".$pageTitle."</h2>";

	/* Aba - Begin */
	echo "<div id='tab' class='tab'>";
	echo "<ul>";
	echo "<li id='litab0' class='tabEndSelected' style='padding-bottom: 6px;'>";
	echo "<a id='atab0' class='tabBeginSelected' href='javascript:mostrarAba(0); '>".
		 "<span  id='spantab0'>Dados</span></a>";
	echo "</li>";
	$k = 1;
	foreach ($formularios as $formulario) {
		echo "<li id='litab".$k."' class='tabEnd' style='padding-bottom: 6px;'>";
		$span = "<span id='spantab".$k."' >";
		echo "<a id='atab".$k."' class='tabBegin' href='javascript:mostrarAba(".$k.");'>".
			 $span.$formulario['Formulario']['name']."</span></a>\n";
		echo "</li>";
		$k++;
	}
	echo "</ul>";
	echo "</div>";
	/* Aba - End */

	echo "<div id='view'>";
	echo "<div id='aba0'>";
	if (!empty($assistido['Assistido']['photo'])) {
		echo $html->image('../assistidos/photo/'.$assistido['Assistido']['id'],array('class'=>'userPhoto'));
	}
	echo "<input type='hidden' id='AssistidoAbaVisivel' value='0'>";
	//echo "<p><label>ID: </label><span>".$assistido['Assistido']['id']."</span></p>";
	echo "<p><label>Nome: </label><span>".$assistido['Assistido']['nome']."</span></p>";
	echo "<p><label>Endereço: </label><span>".$assistido['Assistido']['endereco']."</span></p>";
	echo "<p><label>Bairro: </label><span>".$assistido['Assistido']['bairro']."</span></p>";
	echo "<p><label>RG: </label><span>".$assistido['Assistido']['rg']."</span></p>";
	echo "<p><label>CPF: </label><span>".$assistido['Assistido']['cpf']."</span></p>";
	echo "<p><label>Nascimento: </label><span>".date('d/m/Y',strtotime($assistido['Assistido']['birthdate']))."</span></p>";
	echo "<p><label>Unidade: </label><span>".$assistido['Unit']['nome']."</span></p>";
	if (isset($assistido['Cidade']['nome'])) {
		echo "<p><label>Cidade: </label><span>".$assistido['Cidade']['nome']."</span></p>";
	}else{
		echo "<p><label>Cidade: </label><span></span></p>";
	}
	if (isset($assistido['Cidade']['Estado']['nome'])) {
		echo "<p><label>Estado: </label><span>".$assistido['Cidade']['Estado']['nome']."</span></p>";
	}else{
		echo "<p><label>Estado: </label><span></span></p>";
	}
	//echo "<p><label>Cidade: </label><span>".$assistido['Cidade']['nome']."</span></p>";
	//echo "<p><label>Estado: </label><span>".$assistido['Cidade']['Estado']['nome']."</span></p>";
	echo "<br />";
	echo "</div>";


	$iFvalor = 0;
	$iFvalorText = 0;
	$iFvalorFile = 0;
	$j = 1;

	foreach ($formularios as $formulario) {
		echo "<div id='aba".$j."' style='display:none;'>";
		echo "<h3>".$formulario['Formulario']['name']."</h3>";
		foreach ($formulario["Fcampo"] as $campo) {

			switch ($campo["type"]) {
				case 'string':
					if (!isset($Fvalores[$campo["id"]])) $Fvalores[$campo["id"]] = array('Fvalor'=>array('id'=>null,'string'=>''));
					echo "<p><label>".$campo["name"].": </label><span>".$Fvalores[$campo["id"]]['Fvalor']['string']."</span></p>";
					break;
				case 'inteiro':
					if (!isset($Fvalores[$campo["id"]])) $Fvalores[$campo["id"]] = array('Fvalor'=>array('id'=>null,'inteiro'=>''));
					echo "<p><label>".$campo["name"].": </label><span>".$Fvalores[$campo["id"]]['Fvalor']['inteiro']."</span></p>";
					break;
				case 'data':
					if (!isset($Fvalores[$campo["id"]])) $Fvalores[$campo["id"]] = array('Fvalor'=>array('id'=>null,'data'=>''));
					echo "<p><label>".$campo["name"].": </label><span>".$Fvalores[$campo["id"]]['Fvalor']['data']."</span></p>";
					break;
				case 'texto':
					if (!isset($Fvalores[$campo["id"]])) $Fvalores[$campo["id"]] = array('Fvalortext'=>array('id'=>null,'texto'=>''));
					echo "<p><label>".$campo["name"].": </label><span>".$Fvalores[$campo["id"]]['Fvalortext']['texto']."</span></p>";
					break;
				case 'file':
					if (!isset($Fvalores[$campo["id"]])) $Fvalores[$campo["id"]] = array('Fvalor'=>array('id'=>null,'string'=>''));
					echo "<p><label>".$campo["name"].": </label><span>";
					echo $html->link($Fvalores[$campo["id"]]['Fvalor']['string'],'/fvalores/download/'.$Fvalores[$campo["id"]]['Fvalor']['id']);
					echo "</span></p>";

					if (isset($Fvalores[$campo["id"]]['Fvalor']['image']) && ($Fvalores[$campo["id"]]['Fvalor']['image'] == true)) {
						echo $html->image('../files/'.$Fvalores[$campo['id']]['Fvalor']['realname']);
					}

					// TODO: Checar se o arquivo está disponível
					break;
			}
		}
		$j++;
		echo "</div>";
	}

	/* Botoes - Inicio */
	$entity = 'assistidos';
	$model = 'Assistido';
	$label = 'assistido';
	$label_plural = 'assistidos';

	echo "<div class='buttonBox'>";
	echo "<div class='buttonMinibox'>";
	$listButton = "<span class=\"buttonList\">Listar ".$label_plural."</span>";
	echo html_entity_decode($html->link($listButton, '/'.$entity.'/',array('class'=>'button')));
	echo "</div>";
	echo "<div class='buttonMinibox'>";
	if ($othAuth->hasPermission($entity.'/edit/')) {
		$editButton = "<span class=\"buttonEdit\">Editar ".$label."</span>";
		echo html_entity_decode($html->link($editButton, '/'.$entity.'/edit/'.$assistido[$model]['id'],array('class'=>'button')));
	}
	echo "</div>";
	echo "<div class='buttonMinibox'>";
	if ($othAuth->hasPermission($entity.'/delete/')) {
		$deleteButton = "<span class=\"buttonDelete\">Apagar ".$label."</span>";
		echo html_entity_decode($html->link($deleteButton,'/'.$entity.'/delete/'.$assistido[$model]['id'], array('class'=>'button'), 'Confirma a exclusão deste item?'));
	}
	echo "</div>";
	echo "</div>";
	/* Botoes - Fim */


	echo "</div>";